<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button class="filter-item" type="success" @click="handleSubmit"> 保存 </el-button>
    </div>

    <div class="grid">

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>基本信息</span>
        </div>
        <el-form :model="device">
          <el-form-item label="名称" :label-width="formLabelWidth">
            <el-input v-model="device.name" autocomplete="off" />
          </el-form-item>
          <el-form-item label="自动获取距离-轴名称" :label-width="formLabelWidth">
            <el-input v-model="device.value.condition.DistanceAxisName" autocomplete="off" />
          </el-form-item>
        </el-form>
      </el-card>

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <h3>周围剂量当量率计算</h3>
        </div>
        <el-table
          :data="device.value.tableDataDose"
          stripe
          border
          style="width: 100%"
        >
          <el-table-column prop="Radio" label="辐射质" />
          <el-table-column prop="Distance" label="照射距离/m" />
          <el-table-column prop="H_K_10" label="h_k(10)/Sv*Gy-1" />
        </el-table>
        <upload-excel-component :on-success="handleSuccessExcelDose" :before-upload="beforeUploadExcel" />
      </el-card>

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <h3>γ射线空气比释动能率计算-Co60</h3>
        </div>
        <el-table
          :data="device.value.tableDataAirKermaCo60"
          stripe
          border
          style="width: 100%"
        >
          <el-table-column prop="RadiativeResource" label="放射源" />
          <el-table-column prop="Attenuator" label="衰减片组合" />
          <el-table-column prop="K_1" label="K_1" />
          <el-table-column prop="T0" label="测定标准值时的日期" />
          <el-table-column prop="N1" label="N1" />
          <el-table-column prop="N2" label="N2" />
          <el-table-column prop="N3" label="N3" />
          <el-table-column prop="N4" label="N4" />
        </el-table>
        <upload-excel-component :on-success="handleSuccessExcelAirKermaCo60" :before-upload="beforeUploadExcel" />
      </el-card>

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <h3>γ射线空气比释动能率计算-Cs137</h3>
        </div>
        <el-table
          :data="device.value.tableDataAirKermaCs137"
          stripe
          border
          style="width: 100%"
        >
          <el-table-column prop="RadiativeResource" label="放射源" />
          <el-table-column prop="Attenuator" label="衰减片组合" />
          <el-table-column prop="K_1" label="K_1" />
          <el-table-column prop="T0" label="测定标准值时的日期" />
          <el-table-column prop="N1" label="N1" />
          <el-table-column prop="N2" label="N2" />
          <el-table-column prop="N3" label="N3" />
          <el-table-column prop="N4" label="N4" />
        </el-table>
        <upload-excel-component :on-success="handleSuccessExcelAirKermaCs137" :before-upload="beforeUploadExcel" />
      </el-card>

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <h3>γ射线空气比释动能率计算-Am241</h3>
        </div>
        <el-table
          :data="device.value.tableDataAirKermaAm241"
          stripe
          border
          style="width: 100%"
        >
          <el-table-column prop="RadiativeResource" label="放射源" />
          <el-table-column prop="Attenuator" label="衰减片组合" />
          <el-table-column prop="K_1" label="K_1" />
          <el-table-column prop="T0" label="测定标准值时的日期" />
          <el-table-column prop="N1" label="N1" />
          <el-table-column prop="N2" label="N2" />
          <el-table-column prop="N3" label="N3" />
          <el-table-column prop="N4" label="N4" />
        </el-table>
        <upload-excel-component :on-success="handleSuccessExcelAirKermaAm241" :before-upload="beforeUploadExcel" />
      </el-card>

    </div>

  </div>
</template>

<script>
import { editDevice } from '@/api/device'
import UploadExcelComponent from './components/UploadExcel/index.vue'

const defaultDeviceConfig = {
  name: 'γ射线空气比释动能率计算',
  sn: 'count_gamma0001',
  model: 'FSC_COUNT_GAMMA',
  tag: 'count_gamma',
  position: '位置',
  sub: 'xxx',
  pub: 'xxx',
  value: {
    tableDataAirKermaCo60: [],
    tableDataAirKermaCs137: [],
    tableDataAirKermaAm241: [],
    tableDataDose: [], // 周围剂量当量率表格

    condition: {
      RadiativeResource: 'Co60',
      Attenuator: [1, 2, 3, 4],
      Time: 1,
      Distance: 1, // 距离
      DistanceAxisIndex: 1, // 距离对应轴索引值
      DistanceAxisName: 'Y', // 距离对应轴名称
      t0: 0, // 标准值测量时时间
      t: 0, // 当前日期
      T: 0, // 半衰期
      K_1: 0, // 1米处标准值
      Nc: 1 // 校准因子
    },
    result: {
      Kd_rate: 0, // 空气比释动能率
      Kd: 0, // 空气比释动能
      Kd_unit: 'uGy',
      Hd_rate: 0, // 周围剂量当量率
      Hd: 0, // 周围剂量当量
      Hd_unit: 'uGy',
      time: 'h'
    },
    auto: true // 自动计算
  },
  online: 0,
  status: 0,
  lock: 0,
  order: 4
}

export default {
  name: 'RG601',
  components: { UploadExcelComponent },
  data() {
    return {
      formLabelWidth: '200px',
      device: defaultDeviceConfig
    }
  },
  created() {
    this.device = this.$route.query
  },
  methods: {
    // 提交保存
    handleSubmit() {
      editDevice(this.device).then(response => {
        if (response.code === 200) {
          this.$message({
            type: 'success',
            message: response.message
          })
          this.$router.push({ path: '/device/index' })
        } else this.$message(response.message)
      })
    },
    beforeUploadExcel(file) {
      const isLt1M = file.size / 1024 / 1024 < 1

      if (isLt1M) {
        return true
      }

      this.$message({
        message: 'Please do not upload files larger than 1m in size.',
        type: 'warning'
      })
      return false
    },
    handleSuccessExcelAirKermaCo60({ results, header }) {
      this.device.value.tableDataAirKermaCo60 = results
    },
    handleSuccessExcelAirKermaCs137({ results, header }) {
      this.device.value.tableDataAirKermaCs137 = results
    },
    handleSuccessExcelAirKermaAm241({ results, header }) {
      this.device.value.tableDataAirKermaAm241 = results
    },
    handleSuccessExcelDose({ results, header }) {
      this.device.value.tableDataDose = results
    }

  }
}
</script>

<style lang="scss" scoped>

.row {
  width: 100%;
  display:flex;
  display:-webkit-flex;/*Safari*/
  justify-content:space-around;/*水平排布方式*/
  align-items:center;/*垂直对齐方式*/
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.box-card{
  margin: 10px;
}

</style>
